/*
 * G.cxx
 *
 *  Created on: 1:28:45 PM Nov 26, 2012
 *      Author: Pallab
 * "I have not failed, I have just found 10000 ways that won't work.
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <tuple>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;


#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait(double seconds) {
    double endtime = clock() + (seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}
template<class T>
inline T fastIn() {
    register char c = 0;
    register T a = 0;
    bool neg = false;
    while (c < 33)
        c = getchar();
    while (c > 33) {
        if (c == '-') {
            neg = true;
        } else {
            a = (a * 10) + (c - '0');
        }
        c = getchar();
    }
    return neg ? -a : a;
}
inline void readword(char *buffer) {
    int c, cnt = 0;
    c = getchar();
    while (c >= 0 && c <= ' ') {
        c = getchar();
    }
    if (c < 0) {
        buffer[cnt] = 0;
        return;
    }
    while (c > ' ') {
        buffer[cnt++] = c;
        c = getchar();
    }
    buffer[cnt] = 0;
}
const int MX = 5005;
int people_count;
string people[MX*2];
unordered_map<string,int> mp;
vector<int> adj[MX*2];

inline void encode(string name) {
    if( mp.count(name)>0 )return ;
    mp[name]=++people_count;
    people[people_count]=name;
}
inline void read() {
    int tmp=fastIn<int>();
    string n1,n2;
    people_count=0;
    fo(i,tmp) {
        cin>>n1>>n2;
        encode(n1),encode(n2);
        int u = mp[n1],v=mp[n2];
        adj[u].pb(v),adj[v].pb(u);
    }
}
bool marked[MX*2];
int resolve[MX*2];
inline void solve(int who) {
    int retval=0;
    int bst=0;

    SET(marked,false);
    foit(it,adj[who])marked[*it]=true;

    foE(i,1,people_count) {
        if(i==who)continue;
        if(marked[i])continue;
        int cnt=0;
        foit(it,adj[i]) {
            if( marked[*it] )++cnt;
        }
        if(cnt==bst)++retval;
        else if(cnt>bst) {
            bst=cnt,retval=1;
        }
    }

    resolve[who]=retval;
}
inline void proc() {
    foE(i,1,people_count) {
        solve(i);
    }
    cout<<people_count<<'\n';
    foE(i,1,people_count) {
        cout<<people[i]<<' '<<resolve[i]<<'\n';
    }
}
int main() {
    int kase = 1;
#if defined( xerxes_pc )
    if (!freopen("in1", "r", stdin))
        puts("error opening file in "), assert(0);
    kase = 1;
#endif
    fo(i,kase) {
        read();
        proc();
    }
    return 0;
}

